<template>
  <div class="account-security">
    <el-form label-width="60px">
      <el-form-item label="用户名">
        <el-input v-model="name" />
        <el-button type="primary" class="mod" plain @click="modUserName()">修改</el-button>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="phone" />
        <el-button type="primary" class="mod" plain>修改</el-button>
      </el-form-item>
      <el-form-item label="原密码">
        <el-input type="password" v-model="password.new" />
      </el-form-item>
      <el-form-item label="新密码">
        <el-input type="password" v-model="password.new" />
      </el-form-item>
      <el-form-item label="确认">
        <el-input type="password" v-model="password.confirm" />
        <el-button type="primary" class="mod" plain>修改密码</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import {reactive, ref} from 'vue';

// 从 sessionStorage 中获取存储的用户信息
const userInfoString = sessionStorage.getItem('userInfo');

// 将获取的字符串解析为对象
const userInfo = JSON.parse(userInfoString);
const name = ref(userInfo.name);
const phone = ref(userInfo.phone);

const password = reactive({
  current: '',
  new: '',
  confirm: ''
});

//修改用户名
const modUserName=()=>{

}
const changePassword = () => {
  if (password.new !== password.confirm) {
    return alert('新密码和确认密码不一致');
  }
  console.log('修改密码:', password);
};
</script>

<style scoped>
.account-security {
  max-width: 600px;
  margin: 0 auto;
}
.el-form.item{
  display: flex;
}
.el-input{
  width:200px;
  margin-left:20px;
}
.mod{
  margin-left:20px;
}
</style>
